
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>章节十:单表-增删查改二 · 信息学院</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="李航老师">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-lou/lou.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="chapter11.html" />
    
    
    <link rel="prev" href="chapter9.html" />
    

    </head>
    <body>
         

<div class="book">
  <div class="header-inner">
    <!-- LOGO -->
    <div class="logo"></div>
    <span class="title"></span>

    <!-- Search -->
    
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>


    <!-- Nav -->
    <ul class="header-nav">
      <li>
        <a href="https://space.bilibili.com/378936143" target="_blank">B站</a>
      </li><li>
        <a href="https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzIzMjY0NjU5Ng==&scene=124#wechat_redirect" target="_blank">公众号</a>
      </li><li>
        <a href="https://edu.csdn.net/course/detail/32032" target="_blank">CSDN</a>
      </li>
    </ul>
  </div>

  <div class="book-summary">
    <div class="book-summary-title">文档目录</div>
     
    <nav role="navigation">


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    c语言程序设计
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../c/chapter1.html">
            
                <a href="../c/chapter1.html">
            
                    
                    章节一:初识C语言程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../c/chapter2.html">
            
                <a href="../c/chapter2.html">
            
                    
                    章节二:常用数据类型(整数)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../c/chapter3.html">
            
                <a href="../c/chapter3.html">
            
                    
                    章节三:常用数据类型(浮点型)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../c/chapter4.html">
            
                <a href="../c/chapter4.html">
            
                    
                    章节四:数据类型转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../c/chapter5.html">
            
                <a href="../c/chapter5.html">
            
                    
                    章节五:运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../c/chapter6.html">
            
                <a href="../c/chapter6.html">
            
                    
                    章节六:选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../c/chapter7.html">
            
                <a href="../c/chapter7.html">
            
                    
                    章节七:switch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../c/chapter8.html">
            
                <a href="../c/chapter8.html">
            
                    
                    章节八:for循环
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    Flask Web开发
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="chapter1.html">
            
                <a href="chapter1.html">
            
                    
                    章节一:flask框架入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="chapter2.html">
            
                <a href="chapter2.html">
            
                    
                    章节二:模版渲染
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="chapter3.html">
            
                <a href="chapter3.html">
            
                    
                    章节三:html基本标签
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="chapter4.html">
            
                <a href="chapter4.html">
            
                    
                    章节四:项目拆分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="chapter5.html">
            
                <a href="chapter5.html">
            
                    
                    章节五:路由参数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="chapter6.html">
            
                <a href="chapter6.html">
            
                    
                    章节六:请求与响应
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="chapter7.html">
            
                <a href="chapter7.html">
            
                    
                    章节七:flask-Cookie
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="chapter8.html">
            
                <a href="chapter8.html">
            
                    
                    章节八:模型数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="chapter9.html">
            
                <a href="chapter9.html">
            
                    
                    章节九:单表-增删查改一
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.10" data-path="chapter10.html">
            
                <a href="chapter10.html">
            
                    
                    章节十:单表-增删查改二
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="chapter11.html">
            
                <a href="chapter11.html">
            
                    
                    章节十一:图书管理系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    gitbook文档搭建
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../book/chapter1.html">
            
                <a href="../book/chapter1.html">
            
                    
                    章节一:环境安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../book/chapter2.html">
            
                <a href="../book/chapter2.html">
            
                    
                    章节二:typora使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../book/chapter3.html">
            
                <a href="../book/chapter3.html">
            
                    
                    章节三:电子书搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../book/chapter4.html">
            
                <a href="../book/chapter4.html">
            
                    
                    章节四:插件安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../book/chapter5.html">
            
                <a href="../book/chapter5.html">
            
                    
                    章节五:部署
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>

</nav>
     
  </div>

  <!-- Content nav -->
  <div class="book-anchor">
    <div class="book-anchor-title"></div>

    <div class="book-anchor-body"></div>
  </div>

  <div class="book-body">
    
    <div class="body-inner">
       

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >章节十:单表-增删查改二</a>
    </h1>
</div>



      <div class="page-wrapper" tabindex="-1" role="main">
        <div class="page-inner">
          
<div id="book-search-results">
    <div class="search-noresults">
    
          <section class="normal markdown-section">
             <h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x638C;&#x63E1;&#x5355;&#x8868;&#x9875;&#x9762;&#x6DFB;&#x52A0;</li>
<li>&#x638C;&#x63E1;&#x5355;&#x8868;&#x9875;&#x9762;&#x5220;&#x9664;</li>
<li>&#x638C;&#x63E1;&#x5355;&#x8868;&#x9875;&#x9762;&#x4FEE;&#x6539;</li>
<li>&#x638C;&#x63E1;&#x5355;&#x8868;&#x9875;&#x9762;&#x67E5;&#x8BE2;</li>
</ul>
<h2 id="flask&#x7528;&#x6237;&#x7BA1;&#x7406;">flask&#x7528;&#x6237;&#x7BA1;&#x7406;</h2>
<p>&#x57FA;&#x4E8E;&#x4E0A;&#x7AE0;&#x5185;&#x5BB9;&#x5B8C;&#x5584;&#x9875;&#x9762;&#x5C55;&#x793A;</p>
<h2 id="&#x67E5;&#x8BE2;&#x6240;&#x6709;&#x7528;&#x6237;">&#x67E5;&#x8BE2;&#x6240;&#x6709;&#x7528;&#x6237;</h2>
<p>Views.py&#x4EE3;&#x7801;</p>
<pre><code class="lang-py"><span class="hljs-meta">@blue.route(&apos;/&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment">#&#x67E5;&#x8BE2;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x7528;&#x6237;&#x4FE1;&#x606F;</span>
    users=User.query.all()
    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">&apos;index.html&apos;</span>,users=users)
</code></pre>
<p>Index.html&#x9875;&#x9762;&#x7F16;&#x5199;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;/addUI&quot;</span>&gt;</span>&#x6DFB;&#x52A0;&#x6570;&#x636E;<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">border</span>=<span class="hljs-string">&quot;1px&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot;500px&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x5E8F;&#x53F7;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x59D3;&#x540D;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x5E74;&#x9F84;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x6027;&#x522B;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x5730;&#x5740;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x85AA;&#x8D44;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>&#x64CD;&#x4F5C;<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    {% for u in users%}
        <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{loop.index }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ u.name }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ u.age }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
            {% if u.sex==true %}
                &#x7537;
            {% else %}
              &#x5973;
            {% endif %}
        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ u.address }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ u.salary }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{{ url_for(&apos;b1.delUser&apos;,id=u.id) }}&quot;</span>&gt;</span>&#x5220;&#x9664;<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{{ url_for(&apos;b1.updateUI&apos;,id=u.id)}}&quot;</span>&gt;</span>&#x7F16;&#x8F91;<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
    {% endfor %}


<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<p>&#x9875;&#x9762;&#x5C55;&#x793A;</p>
<p><img src="assets/image-20231116161358473.png" alt="image-20231116161358473"></p>
<h2 id="&#x6DFB;&#x52A0;&#x7528;&#x6237;">&#x6DFB;&#x52A0;&#x7528;&#x6237;</h2>
<p>Views.py</p>
<pre><code class="lang-py"><span class="hljs-comment">#1.&#x8FDB;&#x5165;&#x5230;&#x6DFB;&#x52A0;&#x9875;&#x9762;</span>
<span class="hljs-meta">@blue.route(&apos;/addUI&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">addUI</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">&apos;add.html&apos;</span>)

<span class="hljs-comment">#2.&#x6DFB;&#x52A0;&#x6570;&#x636E;</span>
<span class="hljs-meta">@blue.route(&apos;/add&apos;,methods=[&apos;POST&apos;,&apos;GET&apos;])</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment">#&#x83B7;&#x53D6;&#x8868;&#x5355;&#x4E2D;&#x7684;&#x6570;&#x636E;</span>
    name=request.form.get(<span class="hljs-string">&apos;name&apos;</span>)
    age=request.form.get(<span class="hljs-string">&apos;age&apos;</span>)
    sex=request.form.get(<span class="hljs-string">&apos;sex&apos;</span>)
    address=request.form.get(<span class="hljs-string">&apos;address&apos;</span>)
    salary=request.form.get(<span class="hljs-string">&apos;salary&apos;</span>)
    <span class="hljs-comment">#&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7528;&#x6237;&#x5BF9;&#x8C61;</span>
    u=User()
    u.age=age
    u.name=name
    u.sex=int(sex)
    u.address=address
    u.salary=salary
    <span class="hljs-comment">#&#x6DFB;&#x52A0;&#x6570;&#x636E;</span>
    db.session.add(u)
    db.session.commit()
    <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">&apos;b1.index&apos;</span>))
    <span class="hljs-comment">#return redirect(&apos;/&apos;)</span>
</code></pre>
<p>add.html&#x9875;&#x9762;&#x7F16;&#x5199;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>&#x6DFB;&#x52A0;&#x4FE1;&#x606F;<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">&quot;/add&quot;</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span>&gt;</span>
        &#x59D3;&#x540D;:<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;name&quot;</span>/&gt;</span> <span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>
        &#x5E74;&#x9F84;:<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;number&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;age&quot;</span>/&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>
        &#x6027;&#x522B;:
            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;radio&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;sex&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;1&quot;</span>&gt;</span> &#x7537;
            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;radio&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;sex&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;0&quot;</span> <span class="hljs-attr">checked</span>&gt;</span> &#x5973;
            <span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>
        &#x5730;&#x5740;:<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;address&quot;</span>/&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>
        &#x85AA;&#x8D44;:<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;salary&quot;</span>/&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x6DFB;&#x52A0;&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>&#x9875;&#x9762;&#x5C55;&#x793A;</p>
<p><img src="assets/image-20231116161633520.png" alt="image-20231116161633520"></p>
<p><img src="assets/image-20231116161650898.png" alt="image-20231116161650898"></p>
<h2 id="&#x5220;&#x9664;&#x4FE1;&#x606F;">&#x5220;&#x9664;&#x4FE1;&#x606F;</h2>
<p>views.py</p>
<pre><code class="lang-py"><span class="hljs-comment">#&#x5220;&#x9664;&#x7528;&#x6237;</span>
<span class="hljs-meta">@blue.route(&apos;/del&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">delUser</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment">#&#x83B7;&#x53D6;id&#x7684;&#x503C;</span>
    id=request.args.get(<span class="hljs-string">&apos;id&apos;</span>)
    print(id)
    user=User.query.get(id)
    db.session.delete(user)
    db.session.commit()
    <span class="hljs-comment">#&#x5220;&#x9664;&#x7528;&#x6237;&#x4E4B;&#x540E;&#xFF0C;&#x901A;&#x8FC7;&#x91CD;&#x5B9A;&#x5411;&#xFF0C;&#x91CD;&#x65B0;&#x67E5;&#x8BE2;&#x6570;&#x636E;</span>
    <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">&apos;b1.index&apos;</span>))
</code></pre>
<h2 id="&#x4FEE;&#x6539;&#x4FE1;&#x606F;">&#x4FEE;&#x6539;&#x4FE1;&#x606F;</h2>
<p>views.py</p>
<pre><code class="lang-py"><span class="hljs-comment">#&#x8FDB;&#x5165;&#x5230;&#x7F16;&#x8F91;&#x9875;&#x9762;</span>
<span class="hljs-meta">@blue.route(&apos;/updateUI&apos;)</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">updateUI</span><span class="hljs-params">()</span>:</span>
    id=request.args.get(<span class="hljs-string">&apos;id&apos;</span>)
    user=User.query.get(id)
    <span class="hljs-keyword">return</span> render_template(<span class="hljs-string">&apos;update.html&apos;</span>,user=user)

<span class="hljs-comment">#&#x4FEE;&#x6539;&#x6570;&#x636E;-&gt;&#x5148;&#x67E5;&#x8BE2;&#x5728;&#x4FEE;&#x6539;</span>
<span class="hljs-meta">@blue.route(&apos;/update&apos;,methods=[&apos;POST&apos;])</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">update</span><span class="hljs-params">()</span>:</span>
    <span class="hljs-comment">#&#x83B7;&#x53D6;&#x6570;&#x636E;</span>
    id=request.form.get(<span class="hljs-string">&quot;id&quot;</span>)
    name = request.form.get(<span class="hljs-string">&apos;name&apos;</span>)
    age = request.form.get(<span class="hljs-string">&apos;age&apos;</span>)
    sex = request.form.get(<span class="hljs-string">&apos;sex&apos;</span>)
    address = request.form.get(<span class="hljs-string">&apos;address&apos;</span>)
    salary = request.form.get(<span class="hljs-string">&apos;salary&apos;</span>)
    <span class="hljs-comment">#&#x6839;&#x636E;id&#x67E5;&#x8BE2;</span>
    user=User.query.get(id)
    user.name=name
    user.age=age
    user.sex=int(sex)
    user.address=address
    user.salary=salary
    db.session.commit()
    <span class="hljs-comment">#&#x4FEE;&#x6539;&#x7528;&#x6237;&#x4E4B;&#x540E;&#xFF0C;&#x901A;&#x8FC7;&#x91CD;&#x5B9A;&#x5411;&#xFF0C;&#x91CD;&#x65B0;&#x67E5;&#x8BE2;&#x6570;&#x636E;</span>
    <span class="hljs-keyword">return</span> redirect(url_for(<span class="hljs-string">&apos;b1.index&apos;</span>))
</code></pre>
 
          </section>
          
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>
 
        </div>
      </div>
      
    </div>

     
    <a
      href="chapter9.html"
      class="navigation navigation-prev "
      aria-label="Previous page: 章节九:单表-增删查改一"
    >
      <i class="fa fa-angle-left"></i>
    </a>
     
    <a
      href="chapter11.html"
      class="navigation navigation-next "
      aria-label="Next page: 章节十一:图书管理系统"
    >
      <i class="fa fa-angle-right"></i>
    </a>
      
  </div>
  <script>
    function showModal() {
      document.getElementsByClassName("mask")[0].style.display = "block";
      document.getElementsByClassName("donate-modal")[0].style.display =
        "block";
    }
    // 切换赞赏码
    function showDonateImg(num) {
      let alipay = "";
      let wxpay = ""
      if(num){
        wxpay = "hidden"
      }else{
        alipay = "hidden"
      }
      document.getElementById("wxpay-code").hidden = wxpay;
      document.getElementById("alipay-code").hidden = alipay;
      document.getElementsByName("pay-way")[num].checked = "checked";
    }

    // 关闭赞赏框
    function closeDonateModal() {
      document.getElementsByClassName("mask")[0].style.display = "none";
      document.getElementsByClassName("donate-modal")[0].style.display = "none";
    }

    var gitbook = gitbook || [];
    gitbook.push(function () {
      gitbook.page.hasChanged({"page":{"title":"章节十:单表-增删查改二","level":"1.3.10","depth":2,"next":{"title":"章节十一:图书管理系统","level":"1.3.11","depth":2,"path":"flask/chapter11.md","ref":"flask/chapter11.md","articles":[]},"previous":{"title":"章节九:单表-增删查改一","level":"1.3.9","depth":2,"path":"flask/chapter9.md","ref":"flask/chapter9.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-sharing","-search","-favicon","code","expandable-chapters","theme-lou","back-to-top-button","search-pro","flexible-alerts","chapter-fold"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"search-pro":{},"code":{"copyButtons":true},"theme-lou":{"hide-elements":[".summary .gitbook-link"],"color":"#2096FF","copyright":{"author":"李航老师"},"forbidCopy":true,"logo":"assets/logo.png","titleColor":{"h1":"#8b008b","h2":"#20b2aa","h3":"#a52a2a"},"search-placeholder":"众里寻他千百度","copyrightLogo":"assets/copyright.png","favicon":"assets/favicon.ico","autoNumber":3},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"李航老师","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"themeLou":{"nav":[{"target":"_blank","url":"https://space.bilibili.com/378936143","name":"B站"},{"target":"_blank","url":"https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzIzMjY0NjU5Ng==&scene=124#wechat_redirect","name":"公众号"},{"target":"_blank","url":"https://edu.csdn.net/course/detail/32032","name":"CSDN"}]}},"title":"信息学院","gitbook":"*","description":"Gitbook电子书示例项目"},"file":{"path":"flask/chapter10.md","mtime":"2023-11-16T08:19:05.893Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-12-07T03:21:22.004Z"},"basePath":"..","book":{"language":""}});
    });
  </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-lou/jweixin-1.6.0.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-lou/lou.js"></script>
        
    

    </body>
</html>

